<?php 
/**
* Data stored in atoms is managed by the AtomData class. It is stored in an external file.
*<p>This class implements the basic functionalities for any data contained in atoms.</p>
*<p>The main is the automated get/set-ers: they allow to support growth of any AtomData derivate class
*toward new versions and functionalities. See how get/set works in <i>BasicAtom</i>, this is the exact same
*behaviour with one addendum, for security since the set mathod can be overridden/abused in child classes:
* setting of attributes that have not been previously registered will silently fail. So when you upgrade your 
*class definition make sure somewhere you register the new parameter.</p>
*<p>There is also two static get/set-ers: the purpose is to provide with a way to store temporary data that
*shall not be serialized to disk. Note that these cannot be used inside the constructor but only from PostInitialize
*onward.</p>
*<p>Also, the built-is <i>SetModified</i> allows for automatic saving of the AtomData instance when something
*is changed without user action.</p>
*<p><b>Initialization phase:</b> since the AtomData is create <i>before</i> its Atom is created, all the Atom
*functionalities (like tags, leaves and such) are NOT available. To avoid this and allow proper initialization 
*of content, any derived class from AtomData shall use the <i>PostInitialize()</i> method which is called
*only after everything is in place.</p>
*@package Atoms
*@author Willy Gardiol <willy@gardiol.org>
*@version 1.0
*/
abstract class AtomData extends BaseClassGetSet
{
	/**
	* This is called by Atom __constructor.
	*@param string $atom_id The atom id
	*/
	final public function Initialize( $atom_id )
	{
		$this->InitializeStatic( $atom_id );
		$this->SetModified();
		$this->PostInitialize();
	}
	/**
	* Place here your derived-class inizialization code.
	* This is not abstract because not every derived class needs it. Basically you need it is you need
	* to register some leaves or tags.
	*/
	protected function PostInitialize()
	{
	}

	/**
	*When called, will notify AtomCache to save this AtomData.
	*/
	final public function SetModified()
	{
		$id = $this->GetId();
		AtomCache::DataModified( $id );
		$atom = AtomCache::GetAtom( $id );
		$atom->SetLastUpdate();
	}

	final public function Set( $k, $v )
	{
		if ( ($ret = parent::Set($k, $v)) );
			$this->SetModified();
		return $ret;
	}
}
?>